home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / scanellp.c < prev    next >
Text File  |  1993-12-06  |  4KB  |  134 lines

  1. /**
  2.  ** SCANELLP.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "grx.h"
  25. #include "libgrx.h"
  26. #include "clipping.h"
  27.  
  28. #ifdef __TURBOC__
  29. #define  MAX_R_SQUARE    120
  30. #endif
  31.  
  32. #ifdef __GNUC__
  33. #define  MAX_R_SQUARE    32000
  34. #endif
  35.  
  36. void _GrScanEllipse(
  37.     int xc,int yc,int xa,int ya,
  38.     int filled,
  39.     int is_XOR_color,
  40.     _GrPixelDrawProc pixelproc,
  41.     _GrLineDrawProc  borderproc,
  42.     _GrScanLineProc  scanfillproc,
  43.     void *fillarg)
  44. {
  45.     int x1,x2,y1,y2;
  46.     MOUSE_FLAG;
  47.  
  48.     if(xa < 0) xa = (-xa);
  49.     if(ya < 0) ya = (-ya);
  50.     x1 = xc - xa; y1 = yc - ya;
  51.     x2 = xc + xa; y2 = yc + ya;
  52.     CLIPSORTEDBOX(CURC,x1,y1,x2,y2);
  53.     MOUSE_BLOCK(CURC,x1,y1,x2,y2);
  54.     if(ya == 0) {
  55.         if(xa == 0) (*pixelproc)(xc,yc,fillarg);
  56.         else    (*scanfillproc)(x1,x2,yc,fillarg);
  57.     }
  58.     else if(xa == 0) {
  59.         (*borderproc)(xc,y1,xc,y2,fillarg);
  60.     }
  61.     else if(xa > (MAX_R_SQUARE / ya)) {    /* Bresenheim would overflow !! */
  62.         int points[MAX_ELLIPSE_PTS+1][2];
  63.         int numpts = _GrGenerateEllipse(points,xc,yc,xa,ya);
  64.         if(filled) _GrScanConvexPoly(numpts,points,
  65.         is_XOR_color,
  66.         pixelproc,
  67.         borderproc,
  68.         scanfillproc,
  69.         fillarg
  70.         );
  71.         else _GrDrawPolygon(numpts,points,
  72.         TRUE,
  73.         is_XOR_color,
  74.         pixelproc,
  75.         borderproc,
  76.         fillarg
  77.         );
  78.     }
  79.     else {
  80.         int yasq  = ya * ya;
  81.         int xasq  = xa * xa;
  82.         int xasq2 = xasq << 1;
  83.         int yasq2 = yasq << 1;
  84.         int xasq4 = xasq << 2;
  85.         int yasq4 = yasq << 2;
  86.         int row   = ya;
  87.         int col   = 0;
  88.         int DST   = (xasq2 * (row - 1) * row) + xasq + (yasq2 * (1 - xasq));
  89.         while((xasq * row) > (yasq * col)) {
  90.         if(!filled) {
  91.             (*pixelproc)(xc-col,yc-row,fillarg);
  92.             (*pixelproc)(xc-col,yc+row,fillarg);
  93.             if(col) {
  94.             (*pixelproc)(xc+col,yc-row,fillarg);
  95.             (*pixelproc)(xc+col,yc+row,fillarg);
  96.             }
  97.         }
  98.         if(DST >= 0) {
  99.             if(filled) {
  100.             (*scanfillproc)(xc-col,xc+col,yc-row,fillarg);
  101.             (*scanfillproc)(xc-col,xc+col,yc+row,fillarg);
  102.             }
  103.             row--;
  104.             DST -= xasq4 * row;
  105.         }
  106.         DST += yasq2 * (3 + (col << 1));
  107.         col++;
  108.         }
  109.         DST = (yasq2 * (col + 1) * col) + (xasq2 * (row * (row - 2) + 1)) + ((1 - xasq2) * yasq);
  110.         while(row >= 0) {
  111.         if(!filled) {
  112.             (*pixelproc)(xc-col,yc-row,fillarg);
  113.             (*pixelproc)(xc+col,yc-row,fillarg);
  114.             if(row) {
  115.             (*pixelproc)(xc-col,yc+row,fillarg);
  116.             (*pixelproc)(xc+col,yc+row,fillarg);
  117.             }
  118.         }
  119.         else {
  120.             (*scanfillproc)(xc-col,xc+col,yc-row,fillarg);
  121.             if(row) (*scanfillproc)(xc-col,xc+col,yc+row,fillarg);
  122.         }
  123.         if(DST <= 0) {
  124.             col++;
  125.             DST += yasq4 * col;
  126.         }
  127.         row--;
  128.         DST += xasq2 * (2 - (row << 1));
  129.         }
  130.     }
  131.     MOUSE_UNBLOCK();
  132. }
  133.  
  134.